package com.zy.project1.biz;

import com.zy.project1.BankAccount;
import com.zy.project1.dao.BankDao;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
@RequiredArgsConstructor
public class BankBizImpl implements BankBiz{

    private final BankDao bankDao;


    public List<BankAccount> showAll(){
        List<BankAccount> list=this.bankDao.findAll();
//       if( true ) {
//           throw new RuntimeException("测试异常");
//       }
        System.out.println(   "showAll方法执行了...");
       return list;
    }

    public BankAccount addBankAccount( double money){
        System.out.println("添加账户的业务层");
        Random r=new Random();
        BankAccount bankAccount=new BankAccount();
        bankAccount.setId(r.nextLong(10000000000L));
        bankAccount.setBalance(money);
        BankAccount ba=this.bankDao.addBankAccount(bankAccount);
        return ba;
    }


}
